package com.xauto.pioneer.appuser.model;

import android.content.Context;

import net.tsz.afinal.FinalDb;
import net.tsz.afinal.annotation.sqlite.Id;
import net.tsz.afinal.annotation.sqlite.Table;

import org.json.JSONObject;

/**
 * 银行对象
 * Created by Lemon on 19/04/2017.
 */
@Table(name = "table_bank")
public class Bank extends BaseModel<Bank> {

    /** 银行ID*/
    @Id(column = "bank_id")
    public String bank_id;
    /** 银行名称*/
    public String bank_name;
    /** 银行首字母*/
    public String bank_prefix;

    public String getBank_id() {
        return bank_id;
    }

    public void setBank_id(String bank_id) {
        this.bank_id = bank_id;
    }

    public String getBank_name() {
        return bank_name;
    }

    public void setBank_name(String bank_name) {
        this.bank_name = bank_name;
    }

    public String getBank_prefix() {
        return bank_prefix;
    }

    public void setBank_prefix(String bank_prefix) {
        this.bank_prefix = bank_prefix;
    }

    @Override
    public Bank parse(JSONObject jsonObject) {
        if(jsonObject != null) {
            bank_id = jsonObject.optString("bank_id");
            bank_name = jsonObject.optString("bank_name");
            bank_prefix = jsonObject.optString("bank_prefix");
            return this;
        }
        return null;
    }
    public void saveDb(Context mContext, Bank bank) {
        FinalDb finalDb = FinalDb.create(mContext);
        finalDb.deleteByWhere(Bank.class, "bank_id = \""+bank.bank_id+"\"");
        finalDb.save(bank);
    }
}
